/**
 * MCP Gateway Core
 */

import { Config, MCPServer } from '../types';
import { Logger } from '../utils/logger';

export class Gateway {
  private logger = new Logger('Gateway');
  private running = false;

  constructor(
    private config: Config,
    private servers: MCPServer[]
  ) {}

  async start(): Promise<void> {
    this.logger.info(`Starting MCP Gateway on ${this.config.gateway.host}:${this.config.gateway.port}`);
    this.running = true;
    
    // Start servers
    for (const server of this.servers) {
      await this.startServer(server);
    }
    
    this.logger.info('Gateway started successfully');
  }

  async stop(): Promise<void> {
    this.logger.info('Stopping gateway...');
    this.running = false;
    
    // Stop servers
    for (const server of this.servers) {
      await this.stopServer(server);
    }
    
    this.logger.info('Gateway stopped');
  }

  private async startServer(server: MCPServer): Promise<void> {
    this.logger.info(`Starting server: ${server.name}`);
    server.status = 'running';
  }

  private async stopServer(server: MCPServer): Promise<void> {
    this.logger.info(`Stopping server: ${server.name}`);
    server.status = 'stopped';
  }

  isRunning(): boolean {
    return this.running;
  }

  getServers(): MCPServer[] {
    return this.servers;
  }
}